package com.jingdianjichi.auth.service.impl;


import cn.dev33.satoken.secure.SaSecureUtil;
import com.alibaba.fastjson.JSON;
import com.jingdianjichi.auth.common.enums.AuthUserStatusEnum;
import com.jingdianjichi.auth.common.enums.IsDeletedFlageEnum;
import com.jingdianjichi.auth.domain.convert.AuthRoleBOConverter;
import com.jingdianjichi.auth.domain.convert.AuthUserBOConverter;
import com.jingdianjichi.auth.domain.entity.AuthRoleBO;
import com.jingdianjichi.auth.domain.entity.AuthUserBO;
import com.jingdianjichi.auth.infra.basic.entity.AuthRole;
import com.jingdianjichi.auth.infra.basic.entity.AuthUser;
import com.jingdianjichi.auth.infra.basic.service.AuthRoleService;
import com.jingdianjichi.auth.infra.basic.service.AuthUserService;
import com.jingdianjichi.auth.service.AuthRoleDomainService;
import com.jingdianjichi.auth.service.AuthUserDomainService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 *角色信息表(AuthRole)表服务实现类
 * @since 2024-04-14 23:18:26
 */
@Service
@Slf4j
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService {
    @Resource
    private AuthRoleService authRoleService;

    @Override
    public Boolean add(AuthRoleBO authRoleBO) {
        if (log.isInfoEnabled()) {
            log.info("AuthRoleDomainServiceImpl.add.dto:{}", JSON.toJSONString(authRoleBO));
        }
        AuthRole authRole = AuthRoleBOConverter.INSTANCE.convertBOto(authRoleBO);
        authRole.setIsDeleted(IsDeletedFlageEnum.UN_DELETE.getCode());
        Integer count = authRoleService.add(authRole);
        return count > 0;
    }

    @Override
    public Boolean update(AuthRoleBO authRoleBO) {
        if (log.isInfoEnabled()) {
            log.info("AuthRoleDomainServiceImpl.update.dto:{}", JSON.toJSONString(authRoleBO));
        }
        AuthRole authRole = AuthRoleBOConverter.INSTANCE.convertBOto(authRoleBO);
        Integer count = authRoleService.update(authRole);
        //todo ：有任何更新，都要与缓存进行同步

        return count > 0;
    }

    @Override
    public Boolean delete(AuthRoleBO authRoleBO) {
        if (log.isInfoEnabled()) {
            log.info("AuthRoleDomainServiceImpl.delete.dto:{}", JSON.toJSONString(authRoleBO));
        }
        AuthRole authRole = AuthRoleBOConverter.INSTANCE.convertBOto(authRoleBO);
        authRole.setIsDeleted(IsDeletedFlageEnum.DELETE.getCode());
        Integer update = authRoleService.update(authRole);
        //todo ：有任何更新，都要与缓存进行同步

        return update>0;
    }
}
